var t = getApp();

Page({
    data: {
        sex: 1,
        birthday: "",
        timeSelect: "",
        wechat_openid: t.globalData.wechat_openid
    },
    goInput: function() {
        wx.navigateTo({
            url: "../writeIn/writeIn"
        });
    },
    onLoad: function() {
        var a = this;
        t.globalData.userInfoAll || wx.getUserInfo({
            success: function(e) {
                t.globalData.userInfoAll = e, a.setData({
                    userInfoAll: e
                });
            }
        });
        var e = {
            wechat_openid: t.globalData.wechat_openid
        };
        wx.request({
            url: "https://api.xiongmaomingli.com/api/index/user_info",
            data: e,
            method: "POST",
            success: function(t) {
                200 == t.statusCode && 200 == t.data.code && t.data.result && a.setData({
                    sex: t.data.result.sex,
                    birthday: t.data.result.birth_year + "-" + (t.data.result.birth_month >= 10 ? t.data.result.birth_month : "0" + t.data.result.birth_month) + "-" + (t.data.result.birth_day >= 10 ? t.data.result.birth_day : "0" + t.data.result.birth_day),
                    timeSelect: (t.data.result.birth_hour >= 10 ? t.data.result.birth_hour : "0" + t.data.result.birth_hour) + ":" + (t.data.result.birth_minute >= 10 ? t.data.result.birth_minute : "0" + t.data.result.birth_minute)
                });
            }
        });
    },
    selectSex: function() {
        1 == this.data.sex ? this.setData({
            sex: 2
        }) : this.setData({
            sex: 1
        });
    },
    dateSelect: function(t) {
        var a = t.detail.value;
        this.setData({
            birthday: a
        });
    },
    timeSelect: function(t) {
        var a = t.detail.value;
        this.setData({
            timeSelect: a
        });
    },
    switchToDetail: function() {
        var a = {}, e = t.globalData.userInfoAll;
        a.wechat_avatar = e.userInfo.avatarUrl, a.wechat_nickname = e.userInfo.nickName, 
        a.wechat_openid = t.globalData.wechat_openid, a.wechat_original = JSON.stringify(e), 
        a.sex = this.data.sex;
        var i = this.data.birthday ? this.data.birthday.split("-") : [], s = this.data.timeSelect ? this.data.timeSelect.split(":") : [];
        if (a.birth_year = parseInt(i[0]), a.birth_month = parseInt(i[1]), a.birth_day = parseInt(i[2]), 
        a.birth_hour = parseInt(s[0]), a.birth_minute = parseInt(s[1]), console.log(a), 
        0 == i.length) return wx.showToast({
            title: "出生时间不能为空",
            icon: "none",
            duration: 1e3
        }), !1;
        wx.request({
            url: "https://api.xiongmaomingli.com/api/index/user",
            data: a,
            method: "POST",
            success: function(t) {
                200 == t.statusCode ? wx.navigateTo({
                    url: "../detail/detail"
                }) : wx.showToast({
                    title: t.data.message,
                    icon: "none",
                    duration: 1e3
                });
            }
        });
    },
    onShareAppMessage: function(t) {
        return "button" === t.from && console.log(t.target), {
            path: "/pages/index/index",
            success: function(t) {
                console.log(t);
            },
            fail: function(t) {
                console.log(t);
            }
        };
    }
});